package com.qfedu.edu.exceptionbusinesshandlerservice.queue.listener;

import com.qfedu.edu.exceptionbusinesshandlerservice.service.ExceptionService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
 * @author xiaobobo
 * @title: ExceptionQueueBusinessListener
 * @projectName seckill-fy-2401-parent
 * @description: 异常队列业务的监听
 * @date 2024/11/18  11:29
 */
@Component
public class ExceptionQueueBusinessListener {

    @Autowired
    private ExceptionService exceptionService;

    /**
     * 监听这个队列
     *
     * @param data
     * @param message
     * @param channel
     */
    @RabbitListener(queues = "exceptionQueue")
    public void receive(byte[] data, Message message, Channel channel) throws IOException {
        String msg = new String(data, "UTF-8");
        exceptionService.handlerExceptionBusiness(msg);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),true);
    }


}
